package com.qianfeng.controller;

import com.alibaba.excel.event.Order;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.bean.JsonResult;
import com.qianfeng.pojo.OrderTable;
import com.qianfeng.pojo.UserTable;
import com.qianfeng.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author admin
 * @date 2021/9/23 9:42
 */


@RestController
@RequestMapping("orderUser")
public class OrderController {
    @Autowired
    private OrderService orderService;
    private String uploadFileName;

    //查询数据
    @RequestMapping("findByPage")
    @ResponseBody
    public JsonResult findBypage(
            @RequestParam(value = "page",required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(value = "limit",required = false,defaultValue = "6") Integer pageSize){

        //设置分页参数
        PageHelper.startPage(pageNum,pageSize);
        //查询所有用户
        List<UserTable> users = orderService.findAdd();
        //封装到PageInfo对象中
        PageInfo<UserTable> PageInfo = new PageInfo<UserTable>(users);
        //返回JsonResult对象
        JsonResult jsonResult = JsonResult.ok();
        jsonResult.setCount(PageInfo.getTotal());
        jsonResult.setData(PageInfo.getList());

        return jsonResult;
    }

    @RequestMapping("updateOrder")
    @ResponseBody
    public String updateOrder(OrderTable orderTable){
        System.err.println(orderTable);
        orderService.updateOrderTable(orderTable);
        return "success";
    }

    @RequestMapping("deleteId")
    @ResponseBody
    public String deleteUserById(Integer id){
        orderService.deleteUserById(id);
        return "success";
    }
}
